<template>
  <div class="comment">
    <el-input
            class="input"
            placeholder="请输入菜品名称"
            v-model="keywords"
            clearable>
    </el-input>
    <el-button @click="searchComment" icon="el-icon-search" type="primary">搜索</el-button>
    <el-table v-loading="loading" :data="tableData" class="table">
      <el-table-column
              prop="orderItem.foodImg"
              label="菜品图片"
              width="200">
        <template slot-scope="scope">
          <el-image class="food-img" :src="scope.row.orderItem.foodImg"></el-image>
        </template>
      </el-table-column>
      <el-table-column
              prop="orderItem.foodTitle"
              label="菜品名称"
              width="150">
      </el-table-column>
      <el-table-column
              prop="orderItem.foodDesc"
              label="菜品描述"
              width="200">
      </el-table-column>
      <el-table-column
              prop="orderItem.foodUnitPrice"
              label="菜品单价（元）"
              width="150">
      </el-table-column>
      <el-table-column
          prop="user.nickName"
          label="评价用户"
          width="100">
      </el-table-column>
      <el-table-column
              prop="tag"
              label="评价标签"
              width="150">
      </el-table-column>
      <el-table-column
              prop="content"
              label="评价内容"
              width="600">
      </el-table-column>
    </el-table>
    <el-pagination
            @current-change="changePage"
            class="page"
            background
            layout="prev, pager, next"
            :page-size="pageSize"
            :total="total">
    </el-pagination>
  </div>
</template>

<script>
export default {
  name: "Comment",
  data () {
    return {
      loading: false,
      tableData: [],
      keywords: '',
      pageNum: 1,
      pageSize: 10,
      total: 0
    }
  },
  methods:{
    loadTableData () {
      this.loading = true
      this.$axios.get(`/comment?keywords=${this.keywords}&&pageNum=${this.pageNum}&&pageSize=${this.pageSize}`).then(res => {
        this.loading = false
        if (res.code === 200) {
          this.tableData = res.data.records
          this.total = res.data.total
        }
      })
    },
    searchComment() {
      this.pageNum = 1
      this.loadTableData()
    },
    changePage (pageNum) {
      this.pageNum = pageNum
      this.loadTableData()
    }
  },
  mounted() {
    this.loadTableData()
  }
}
</script>

<style lang="scss" scoped>
  .comment {
    height: 100%;
    width: 100%;
    .input {
      width: 300px;
      margin: 0 20px 0 0;
    }
    .table {
      width: 100%;
      margin-top: 20px;
      .food-img {
        border-radius: 6px;
        overflow: hidden;
        width: 100px;
        height: 100px;
      }
    }
    .page {
      margin: 20px 0;
    }
  }
</style>
